<template>
  <a-spin :spinning="loading">
    <teacher-result-detail v-if="inited" :user-name="username" :date="this.date" :teacher-count="teacherCount" :teacher-base-info="teacherBaseInfo" :isview="true"></teacher-result-detail>
  </a-spin>

</template>

<script>
import TeacherResultDetail from '@views/gfxy/result/teacherResultDetail'
import { getCurrentDate } from '@api/api'
import store from '@/store'
import Vue from 'vue'
import { USER_INFO,USER_ROLES } from "@/store/mutation-types"
import { getAction } from '@api/manage'
import TeacherResultService from '@views/gfxy/result/modules/teacherResultService'
export default {
  name: 'TeacherDetail',
  components: { TeacherResultDetail },
  props: {
    userName: {
      type: String,
      required: false
    },
    date:{
      type: String,
      required: false
    }
  },
  created(){
    // this.date = this.dateP;
    getAction('/sys/user/queryById' ,{id: this.userName})
      .then((res)=>{
        console.log(res);
        let userInfo = res.result;
        this.username = userInfo.username;
        this.init(userInfo.username);
      })
  },
  data(){
    return {
      loading : false,
      inited: false,
      teacherCount:{},
      username:'',
      teacherBaseInfo:{},
      url:{
        getTeacherScoreUrl:'index/teacherIndex/getTeacherScoreAndRankedByUsernameAndDate',
        getTeacherBaseInfoUrl:'index/teacherIndex/getTeacherBaseInfoByUserName'
      }
    }
  },
  methods:{
    init(username){
      this.loading = true;
      getAction('/index/teacherIndex/getTeacherCount' ,{username: username}).then((res)=>{
        console.log(res)
        if(res.success){
          this.teacherCount = res.result;
        }else{
          this.$message.warning(res.message);
        }

        getAction(this.url.getTeacherBaseInfoUrl, { username: this.username }).then((res) => {
          if (res.success) {
            if(res.result.length == 1){
              this.teacherBaseInfo = res.result[0];
              console.log("teacherBaseInfo:", this.teacherBaseInfo);
            } else {
              this.$message.warning(res.message);
            }
          }
          this.inited = true;
        }).finally(() => {
          this.loading = false;
        });


      }).finally(() => {
        this.loading = false;
      })
    },

  },
  mounted() {
    let roles = Vue.ls.get(USER_ROLES);
  }
}
</script>

<style lang="less" scoped>

</style>